<template>
  <div>
    <MyHeader title="TabBar案例"></MyHeader>
    <!-- 中间部分通过动态组件实现页面切换 -->
    <div class="main">
      <!-- 组件缓存 -->
      <keep-alive>
        <!-- 动态组件 -->
        <component :is="comName"></component>
      </keep-alive>
    </div>
    <MyTabBar @changeCom="changeComFn" :arr="tabList"></MyTabBar>
  </div>
</template>

<script>
// 🔔 头部组件是复用购物车案例的那个
import MyHeader from "./components/MyHeader.vue";
import MyTabBar from "./components/MyTabBar.vue";
// 1. 新建组件 - 在views 文件夹下新建3个页面组件
// 2. 引入 3 个页面组件
// 3. 注册 3 个页面组件
// 4. 通过 <component is=""></component> 使用组件
import MyGoodsList from "./views/MyGoodsList.vue";
import MyGoodsSearch from "./views/MyGoodsSearch.vue";
import MyUserInfo from "./views/MyUserInfo.vue";
export default {
  data() {
    return {
      comName: 'MyGoodsList',
      tabList: [
        {
          iconText: "icon-shangpinliebiao",
          text: "商品列表",
          componentName: "MyGoodsList",
        },
        {
          iconText: "icon-sousuo",
          text: "商品搜索",
          componentName: "MyGoodsSearch",
        },
        {
          iconText: "icon-user",
          text: "我的信息",
          componentName: "MyUserInfo",
        },
      ],
    };
  },
  components: {
    MyHeader,
    MyTabBar,
    MyGoodsList,
    MyGoodsSearch,
    MyUserInfo,
  },
  methods: {
    // 修改动态组件的变量名，实现动态组件切换
    changeComFn(theComName){
      this.comName = theComName
    }
  }
};
</script>

<style>
.main{
  padding-top: 45px;
  padding-bottom: 50px;
}
</style>